/*
 * Created by JFormDesigner on Mon Jun 27 01:11:47 CST 2022
 */

package com.keshe.jsp;

import com.keshe.service.RoomContorller;
import com.keshe.service.UserContorller;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author 1
 */
public class UpdatePassword extends JFrame {
    public UpdatePassword() {
        initComponents();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");
        panel1 = new JPanel();
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        label3 = new JLabel();
        passwordField1 = new JPasswordField();
        label4 = new JLabel();
        passwordField2 = new JPasswordField();
        panel2 = new JPanel();
        button1 = new JButton();
        button2 = new JButton();
        panel3 = new JPanel();
        action1 = new updatepassword();
        action2 = new Return1();

        //======== this ========
        Container contentPane = getContentPane();

        //======== panel1 ========
        {

            //---- label1 ----
            label1.setText(bundle.getString("label1.text_13"));
            label1.setIcon(new ImageIcon(getClass().getResource("/images/\u7528\u6237\u540d.png")));

            //---- label2 ----
            label2.setText(bundle.getString("label2.text_6"));
            label2.setIcon(new ImageIcon(getClass().getResource("/images/\u5bc6\u7801.png")));

            //---- label3 ----
            label3.setText(bundle.getString("label3.text_4"));
            label3.setHorizontalAlignment(SwingConstants.CENTER);
            label3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 26));
            label3.setIcon(new ImageIcon(getClass().getResource("/images/\u9152\u5e97 (1).png")));

            //---- label4 ----
            label4.setText(bundle.getString("label4.text"));
            label4.setIcon(new ImageIcon(getClass().getResource("/images/\u5bc6\u7801.png")));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addComponent(label3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addGroup(panel1Layout.createParallelGroup()
                            .addComponent(label2)
                            .addComponent(label1)
                            .addComponent(label4))
                        .addGap(23, 23, 23)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                            .addComponent(passwordField1, GroupLayout.PREFERRED_SIZE, 211, GroupLayout.PREFERRED_SIZE)
                            .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 211, GroupLayout.PREFERRED_SIZE)
                            .addComponent(passwordField2, GroupLayout.PREFERRED_SIZE, 211, GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(73, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(label3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(textField1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(label1))
                        .addGap(20, 20, 20)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(passwordField1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(label2))
                        .addGap(18, 18, 18)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label4)
                            .addComponent(passwordField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGap(5, 5, 5))
            );
        }

        //======== panel2 ========
        {

            //---- button1 ----
            button1.setAction(action1);

            //---- button2 ----
            button2.setAction(action2);

            GroupLayout panel2Layout = new GroupLayout(panel2);
            panel2.setLayout(panel2Layout);
            panel2Layout.setHorizontalGroup(
                panel2Layout.createParallelGroup()
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(button1)
                        .addGap(90, 90, 90)
                        .addComponent(button2)
                        .addContainerGap(94, Short.MAX_VALUE))
            );
            panel2Layout.setVerticalGroup(
                panel2Layout.createParallelGroup()
                    .addGroup(GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(panel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(button1)
                            .addComponent(button2)))
            );
        }

        //======== panel3 ========
        {

            GroupLayout panel3Layout = new GroupLayout(panel3);
            panel3.setLayout(panel3Layout);
            panel3Layout.setHorizontalGroup(
                panel3Layout.createParallelGroup()
                    .addGap(0, 425, Short.MAX_VALUE)
            );
            panel3Layout.setVerticalGroup(
                panel3Layout.createParallelGroup()
                    .addGap(0, 20, Short.MAX_VALUE)
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addComponent(panel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(panel2, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addGap(8, 8, 8))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JLabel label3;
    private JPasswordField passwordField1;
    private JLabel label4;
    private JPasswordField passwordField2;
    private JPanel panel2;
    private JButton button1;
    private JButton button2;
    private JPanel panel3;
    private updatepassword action1;
    private Return1 action2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    private class updatepassword extends AbstractAction {
        private updatepassword() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action1.Name_15"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            UserContorller uc=new UserContorller();
            int flag=uc.updatePassword(textField1.getText(), String.valueOf(passwordField1.getPassword()),String.valueOf(passwordField2.getPassword()));
            if(flag==-2){
                JOptionPane.showMessageDialog(null,"请完善信息再确认！");
            }if(flag==-1){
                JOptionPane.showMessageDialog(null,"原密码错误，请重新输入！");
            }if(flag==1){
                JOptionPane.showMessageDialog(null,"修改成功！");
                dispose();
                new Login().setVisible(true);
            }if(flag==0){
                JOptionPane.showMessageDialog(null,"修改失败！");
            }if(flag==-3){
                JOptionPane.showMessageDialog(null,"该账号尚未注册！");
            }
        }
    }

    private class Return1 extends AbstractAction {
        private Return1() {
            // JFormDesigner - Action initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
            ResourceBundle bundle = ResourceBundle.getBundle("com.keshe.jsp.form");

            putValue(NAME, bundle.getString("action2.Name_9"));
            // JFormDesigner - End of action initialization  //GEN-END:initComponents
        }

        public void actionPerformed(ActionEvent e) {
            // TODO add your code here
            dispose();
            new UserManager().setVisible(true);
        }
    }
}
